home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 273_01.zip / BEEP.CC next >
Text File  |  1993-04-04  |  1KB  |  45 lines

  1. #include <dos.h>
  2. #include <conio.h>
  3.  
  4. #define  ONTONE  outportb( 0x61, inport( 0x61 ) | 3 )
  5. #define  OFFTONE outportb( 0x61, inport( 0x61 ) & 0xFC )
  6. static void setfreq(unsigned int);
  7. static unsigned long int getticks();
  8.  
  9. void     beep(unsigned int pitch, unsigned int nticks )
  10. /* Sound the speaker using indicated pitch for nticks long
  11.    for error sound use beep(440,3) beep(220,3)
  12. */       
  13. {
  14. unsigned long int ticks,ticksa;
  15.  
  16.     setfreq( pitch );
  17.     ticksa = getticks();
  18.     while ( ( ticks = getticks() ) == ticksa )
  19.         ;
  20.     ONTONE;
  21.     ticks = ticks + (unsigned long int) nticks;
  22.     while ( getticks() < ticks )
  23.         ;
  24.     OFFTONE;
  25. }
  26.  
  27.  
  28. static void setfreq(unsigned int count )
  29. {
  30.  
  31.     outp( 0x43, 0xB6 );
  32.     outp( 0x42, (int) (count & 0xFF) );
  33.     outp( 0x42, (int) (count >> 8) );
  34. }
  35.  
  36. static unsigned long int getticks()
  37. {
  38. union   REGS regs;
  39.  
  40.     regs.h.ah = 0x00;
  41.     int86( 0x1A, ®s, ®s );
  42.     return( ((unsigned long int) regs.x.cx << 16) + regs.x.dx );
  43. }
  44.  
  45.